package com.laomuji.android.mvvm.http.service

import com.laomuji.android.mvvm.http.encrypt.EncryptFactory
import com.laomuji.android.mvvm.http.entity.request.TestRequestEntity
import com.laomuji.android.mvvm.http.entity.response.TestResponseEntity
import io.reactivex.Observable
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query
import retrofit2.http.Url

/**
 * 内部Service,存放所有内部的Http请求
 * @author laomuji666
 * @since 2024/2/20
 */
interface Service {
    /**
     * POST请求
     * From参数,使用@FieldMap或者@Field
     */
    @FormUrlEncoded
    @POST("/login/test")
    fun fromLogin(@FieldMap map:Map<String,String>): Observable<TestResponseEntity>

    /**
     * POST请求
     * JSon参数,使用实体的方式
     */
    @POST("/login/test")
    fun jsonLogin(@Body body: TestRequestEntity): Observable<TestResponseEntity>

    /**
     * POST请求
     * Body加密,在StandardInterceptor里拦截了请求头,分析是否需要加密
     */
    @Headers("${EncryptFactory.EncryptKey.ENCRYPT_HEADER_KEY}:${EncryptFactory.EncryptKey.BASE64}")
    @POST("/login/test")
    fun encodeBody(@Body body: TestRequestEntity): Observable<TestResponseEntity>

    /**
     * GET请求
     * 路径参数使用@Path
     * 查询参数使用@Query
     */
    @GET("https://www.facebook.com/{tr}?noscript=1")
    fun facebookEvent(@Path("tr")tr:String,@Query("id")id:String,@Query("ev") ev:String): Observable<String>

    /**
     * 上传阿里OSS
     */
    @PUT
    @Headers("Content-Type:application/octet-stream;charset=utf-8")
    fun uploadOSS(@Url url: String?, @Body body: RequestBody?): Observable<String>


    /**
     * 上传多个文件
     * 可以传query参数,但不能传body参数
     */
    @Multipart
    @POST("/upload")
    fun uploadFiles(@Query("type") type: String, @Part files: Array<MultipartBody.Part>): Observable<String>
}